// mircoApp/kaipin_laboratory/comment/comment.js
const skinBehavior = require('../../../utils/themeSkin/skinBehavior');
const app = getApp();
Page({
  behaviors: [skinBehavior],

  /**
   * 页面的初始数据
   */
  data: {
    img_url: '',
    list: [],
    page: 1,
    total_page: 0,
    id: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.id = options.store_id || "";
  },
  goto() {
    wx.navigateTo({
      url: '/mircoApp/kaipin_laboratory/publish_comment/publish_comment?id=' + this.data.id,
    })
  },

  getData(page = 1) {
    app._postNetWork({
      url: app.getNetAddresss("plugin.local-life.api.store.comment-list"),
      data: {
        store_id: this.data.id,
        page
      },
      success: resdata => {
        let {
          result,
          data
        } = resdata.data;
        if (result) {
          let list = data.current_page == 1 ? data.data : this.data.list.concat(data.data)
          this.setData({
            list
          })
          this.data.page = data.current_page;
          this.data.total_page = data.last_page;
        }
      }
    })
  },
  getMoreData() {
    if (this.data.page >= this.data.total_page) return;
    let page = this.data.page + 1;
    this.getData(page);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData()
    let yz_basic_inf = wx.getStorageSync('yz_basic_info');
    let img_url = yz_basic_inf.host + 'kaipin-laboratory/empty.png';
    this.setData({
      img_url
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getMoreData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})